package com.ldk.admin.controller;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.ldk.framework.entity.AppVersion;
import com.ldk.framework.service.IAppVersionService;

@Controller
@RequestMapping("/app")
public class AppDownloadController {
	
	@Autowired
	private IAppVersionService appVersionService;

	@RequestMapping("/download")
	public ModelAndView download(ModelMap map){
		
		AppVersion query = new AppVersion();
		query.setEnabled(true);
		query.setPlatform(2+"");//2安卓用户端
		
		AppVersion androidClient = appVersionService.selectOne("", query);
		if(androidClient != null && !StringUtils.isBlank(androidClient.getDownUrl())){
			map.addAttribute("androidClientUrl", androidClient.getDownUrl());
		}
		query.setPlatform(1+"");//2苹果用户端
		AppVersion iosClient = appVersionService.selectOne("", query);
		if(iosClient != null && !StringUtils.isBlank(iosClient.getDownUrl())){
			map.addAttribute("iosClientUrl", iosClient.getDownUrl());
		}
		query.setPlatform(4+"");//4安卓司机端
		AppVersion androidDriver = appVersionService.selectOne("", query);
		if(androidDriver != null && !StringUtils.isBlank(androidDriver.getDownUrl())){
			map.addAttribute("androidDriverUrl", androidDriver.getDownUrl());
		}

		query.setPlatform(8+"");//8苹果司机端
		AppVersion iosDriver = appVersionService.selectOne("", query);
		if(iosDriver != null && !StringUtils.isBlank(iosDriver.getDownUrl())){
			map.addAttribute("iosDriverUrl", iosDriver.getDownUrl());
		}
		
		return new ModelAndView("download");
	}
}
